package com.example.dormitory.service;


import com.example.dormitory.entity.*;
import com.example.dormitory.mapper.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class InformService {

    @Autowired
    private InformMapper informMapper;

    public int create(Inform inform) {
        return informMapper.create(inform);
    }

    public int delete(String ids) {
        String[] arr = ids.split(",");
        int row = 0;
        for (String s : arr) {
            if(!StringUtils.isEmpty(s)){
                informMapper.delete(Integer.parseInt(s));
            row++;
            }
        }
        return row;
    }

    public int delete(Integer id) {
        return informMapper.delete(id);
    }

    public int update(Inform inform) {
        return informMapper.update(inform);
    }

    public int updateSelective(Inform inform) {
        return informMapper.updateSelective(inform);
    }

    public PageInfo<Inform> query(Inform inform) {
        if(inform != null && inform.getPage() != null){
            PageHelper.startPage(inform.getPage(),inform.getLimit());
        }
        return new PageInfo<Inform>(informMapper.query(inform));
    }

    public Inform detail(Integer id) {
        return informMapper.detail(id);
    }

    public int count(Inform inform) {
        return informMapper.count(inform);
    }
}
